import React, {Component} from 'react';
import AroToast from './AroToast';

export default class ToastManager  {
  static toast;

  static show(text, duration) {
    this.toast && this.toast.show(text, duration);
  }

  static hide() {
    this.toast && this.toast.hide();
  }

  static netError() {
    this.show('网络错误，请稍后重试！', 2000);
  }

}

export class Toast extends Component {

  componentWillUnmount() {
    ToastManager.toast = null;
  }

  render() {
    return (<AroToast ref={e => ToastManager.toast = e} position={'top'} />)
  }
}